/**
 * 添加或者修改页面
 */
var TaskInfoDlg = {
    data: {
        cashier: "",
        coke: "",
        supplier: "",
        openTime: "",
        distribution: ""
    }
};

layui.use(['form', 'admin', 'ax', 'laydate', 'upload'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var laydate = layui.laydate;
    var upload = layui.upload;

    // 图片压缩
    function canvasDataURL(file, callback) { //压缩转化为base64
        var reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = function (e) {
            const img = new Image();
            const quality = 0.2 // 图像质量比例
            const canvas = document.createElement('canvas');
            const drawer = canvas.getContext('2d');
            img.src = this.result;
            img.onload = function () {
                canvas.width = img.width;
                canvas.height = img.height;
                drawer.drawImage(img, 0, 0, canvas.width, canvas.height);
                convertBase64UrlToBlob(canvas.toDataURL(file.type, quality), callback);
            }
        }
    }

    function convertBase64UrlToBlob(urlData, callback) { //将base64转化为文件格式
        const arr = urlData.split(',');
        const mime = arr[0].match(/:(.*?);/)[1];
        const bstr = atob(arr[1]);
        let n = bstr.length;
        const u8arr = new Uint8Array(n);
        while (n--) {
            u8arr[n] = bstr.charCodeAt(n)
        }
        callback(new Blob([u8arr], {
            type: mime
        }));
    }

    //开业时间选择框
    laydate.render({
        elem: '#openTime',
        trigger: 'click',
    });
    //预估开业时间选择框
    laydate.render({
        elem: '#ygTime',
        trigger: 'click',
    });
    //租房时间选择框
    laydate.render({
        elem: '#rentingData',
        trigger: 'click',
    });

    //营业执照年审日期选择框
    laydate.render({
        elem: '#yyrq',
        trigger: 'click',
    });

    //食品经营许可证截止日期选择框
    laydate.render({
        elem: '#wsrq',
        trigger: 'click',
    });
    //到货日期选择框
    if($("#arrival").val() != '已到货'){
        laydate.render({
            elem: '#distribution',
            trigger: 'click',
        });
    } else {
        $('#distribution').css('background','#E1E2E6');
        $('#distribution').attr("disabled", "disabled");
        $('#note').attr("disabled", "disabled");
        $('#note').css('background','#E1E2E6');
    }
    if($("#arrival").val() != '已发货'){
        laydate.render({
            elem: '#distribution',
            trigger: 'click',
        });
    } else {
        $('#distribution').css('background','#E1E2E6');
        $('#distribution').attr("disabled", "disabled");
        $('#note').attr("disabled", "disabled");
        $('#note').css('background','#E1E2E6');
    }

    //让当前iframe弹层高度适应
    admin.iframeAuto();

    // 上传营业执照
    var arr = [];
    upload.render({
        elem: '#many_wwztimg_upload_btn'
        , url: '/task/uploads' //改成您自己的上传接口
        , multiple: true
        , auto: false
        , before: function (obj) {
            //预读本地文件示例，不支持ie8
            // obj.preview(function(index, file, result){
            //     $('#uploader-list').append('<img style="width: 80px;height: 80px;" src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img">')
            // });
        }
        // 图片压缩
        , choose: function (obj) { //选择文件后的回调
            var files = obj.pushFile();
            var filesArry = [];
            for (var key in files) { //将上传的文件转为数组形式
                filesArry.push(files[key])
            }
            var index = filesArry.length - 1;
            var file = filesArry[index]; //获取最后选择的图片,即处理多选情况

            if (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion.split(";")[1]
                .replace(/[ ]/g, "").replace("MSIE", "")) < 9) {
                return obj.upload(index, file)
            }
            canvasDataURL(file, function (blob) {
                var aafile = new File([blob], file.name, {
                    type: file.type
                });
                var isLt1M;
                if (file.size < aafile.size) {
                    isLt1M = file.size
                } else {
                    isLt1M = aafile.size
                }
                if (isLt1M / 1024 / 1024 > 2) {
                    return layer.alert('上传图片过大！')
                } else {
                    if (file.size < aafile.size) {
                        return obj.upload(index, file)
                    }
                    obj.upload(index, aafile)
                }
            })
        }
        , done: function (res) {
            //获取到图片拼接展示
            $("#uploader-list-wwztimg").append(
                '<div id="pic" class="file-iteme">' +
                '<div class="handle"><span class="layui-icon">点击删除</span></div>' +
                "<div class='gs-upload-file-container'>" +
                "<div class='gs-upload-ele'>" +
                "<div class='progress-bar progress-bar-success progress-bar-striped gs-upload-progress-bar' style='width: 188px; display: none;'></div>" +
                "<div class='gs-upload-ele-img-div'>" +
                "<img class='gs-upload-ele-img' src='" + res.data.src + "' style='cursor: pointer;width: 80px;height: 80px;'>" +
                "</div>	" +
                "<div class='gs-upload-ele-content'>" +
                "<div class='gs-upload-ele-title-div'></div>" +
                "<div class='gs-upload-ele-menu'>" +
                "</div></div></div></div></div>"
            );
            //图片预览
            layer.photos({
                photos: '#uploader-list-wwztimg',
                anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
            });
            //上传完毕
            arr.push(res.data.src);
            $("#wwztimg").val(arr);
        }
    });


    // 上传法人身份证
    var arr8 = [];
    upload.render({
        elem: '#many_xsjztimg_upload_btn'
        , url: '/task/uploads' //改成您自己的上传接口
        , multiple: true
        , auto: false
        , before: function (obj) {
            // this.data={'dm':$('#dm').val()};
            //预读本地文件示例，不支持ie8
            // obj.preview(function(index, file, result){
            //     $('#uploader-list').append('<img style="width: 80px;height: 80px;" src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img">')
            // });
        }
        , choose: function (obj) { //选择文件后的回调
            var files = obj.pushFile();
            var filesArry = [];
            for (var key in files) { //将上传的文件转为数组形式
                filesArry.push(files[key])
            }
            var index = filesArry.length - 1;
            var file = filesArry[index]; //获取最后选择的图片,即处理多选情况

            if (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion.split(";")[1]
                .replace(/[ ]/g, "").replace("MSIE", "")) < 9) {
                return obj.upload(index, file)
            }
            canvasDataURL(file, function (blob) {
                var aafile = new File([blob], file.name, {
                    type: file.type
                });
                var isLt1M;
                if (file.size < aafile.size) {
                    isLt1M = file.size
                } else {
                    isLt1M = aafile.size
                }
                if (isLt1M / 1024 / 1024 > 2) {
                    return layer.alert('上传图片过大！')
                } else {
                    if (file.size < aafile.size) {
                        return obj.upload(index, file)
                    }
                    obj.upload(index, aafile)
                }
            })
        }
        , done: function (res) {
            //获取到图片拼接展示
            $("#uploader-list-xsjztimg").append(
                '<div id="pic" class="file-iteme">' +
                '<div class="handle"><span class="layui-icon">点击删除</span></div>' +
                "<div class='gs-upload-file-container'>" +
                "<div class='gs-upload-ele'>" +
                "<div class='progress-bar progress-bar-success progress-bar-striped gs-upload-progress-bar' style='width: 188px; display: none;'></div>" +
                "<div class='gs-upload-ele-img-div'>" +
                "<img class='gs-upload-ele-img' src='" + res.data.src + "' style='cursor: pointer;width: 80px;height: 80px;'>" +
                "</div>	" +
                "<div class='gs-upload-ele-content'>" +
                "<div class='gs-upload-ele-title-div'></div>" +
                "<div class='gs-upload-ele-menu'>" +
                "</div></div></div></div></div>"
            );
            //图片预览
            layer.photos({
                photos: '#uploader-list-xsjztimg',
                anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
            });
            //上传完毕
            arr8.push(res.data.src);
            $("#xsjztimg").val(arr8);
        }
    });

    //食品经营许可证上传
    var arr2 = [];
    upload.render({
        elem: '#many_dgztimg_upload_btn'
        , url: '/task/uploads' //改成您自己的上传接口
        , multiple: true
        , auto: false
        , before: function (obj) {
            //this.data = {'dm': $('#dm').val()};
            //预读本地文件示例，不支持ie8
            // obj.preview(function(index, file, result){
            //     $('#uploader-list').append('<img style="width: 80px;height: 80px;" src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img">')
            // });
        }
        , choose: function (obj) { //选择文件后的回调
            var files = obj.pushFile();
            var filesArry = [];
            for (var key in files) { //将上传的文件转为数组形式
                filesArry.push(files[key])
            }
            var index = filesArry.length - 1;
            var file = filesArry[index]; //获取最后选择的图片,即处理多选情况

            if (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion.split(";")[1]
                .replace(/[ ]/g, "").replace("MSIE", "")) < 9) {
                return obj.upload(index, file)
            }
            canvasDataURL(file, function (blob) {
                var aafile = new File([blob], file.name, {
                    type: file.type
                });
                var isLt1M;
                if (file.size < aafile.size) {
                    isLt1M = file.size
                } else {
                    isLt1M = aafile.size
                }
                if (isLt1M / 1024 / 1024 > 2) {
                    return layer.alert('上传图片过大！')
                } else {
                    if (file.size < aafile.size) {
                        return obj.upload(index, file)
                    }
                    obj.upload(index, aafile)
                }
            })
        }
        , done: function (res) {
            //获取到图片拼接展示
            $("#uploader-list-dgztimg").append(
                '<div id="pic" class="file-iteme">' +
                '<div class="handle"><span class="layui-icon">点击删除</span></div>' +
                "<div class='gs-upload-file-container'>" +
                "<div class='gs-upload-ele'>" +
                "<div class='progress-bar progress-bar-success progress-bar-striped gs-upload-progress-bar' style='width: 188px; display: none;'></div>" +
                "<div class='gs-upload-ele-img-div'>" +
                "<img class='gs-upload-ele-img' src='" + res.data.src + "' style='cursor: pointer;width: 80px;height: 80px;'>" +
                "</div>	" +
                "<div class='gs-upload-ele-content'>" +
                "<div class='gs-upload-ele-title-div'></div>" +
                "<div class='gs-upload-ele-menu'>" +
                "</div></div></div></div></div>"
            );
            //图片预览
            layer.photos({
                photos: '#uploader-list-dgztimg',
                anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
            });
            //上传完毕
            arr2.push(res.data.src);
            $("#dgztimg").val(arr2);
        }
    });

    // 宿舍信息
    var _delay = false
    $("#23").click(function () {
        if(_delay) {
            layer.msg('请勿多次点击提交！');
            return;
        };
        _delay = true;
        setTimeout(() =>{
            _delay = false
        },2000);
        var rentingData = $('#rentingData').val();
        var prices = $('#prices').val();
        var deposit = $('#deposit').val();
        var area = $('#area').val();
        var address = $('#address').val();
        var phone = $('#phone').val();
        var list = [];
        $("#zf .name").each(function (o, e) {
            var object = {};
            object.proId = $("#proId").val();
            object.taskId = $(e).next().find('.taskId').val();
            object.content = $(e).next().find('.msg').val().trim();
            object.taskName = $(e).html().trim();
            if ($(e).next().find('.msg').val() != null && $(e).next().find('.msg').val() != "") {
                list.push(object);
            }
        });

        if (rentingData == '') {
            layer.msg('请选择日期！', {icon: 2,});
            return
        } else if (prices == '') {
            layer.msg('请填写价格！', {icon: 2,});
            return
        } else if (deposit == '') {
            layer.msg('请填写押金！', {icon: 2,});
            return
        } else if (area == '') {
            layer.msg('请填写面积！', {icon: 2,});
            return
        } else if (address == '') {
            layer.msg('请填写地址！', {icon: 2,});
            return
        } else if (phone == '') {
            layer.msg('请填写房东电话！', {icon: 2,});
            return
        } else {
            $.ajax({
                type: "post",
                url: "/task/addRentAdmin",
                data: JSON.stringify(list),
                contentType: 'application/json',
                async: false,
                success: function (rs) {
                    if(rs.success){
                        list = [];
                        layer.msg('提交成功！', {icon: 1},);
                        $('#23').hide();
                        window.location.reload();
                    }else{
                        Feng.error(rs.message);
                    }
                }, error: function (rs) {
                    list = [];
                    Feng.error(rs.responseJSON.message);
                    // window.location.reload();
                }
            });
        }

    });

    // 开业时间提交
    var _delay = false
    $('#16').click(function () {
        if(_delay) {
            layer.msg('请勿多次点击提交！');
            return;
        };
        _delay = true;
        setTimeout(() =>{
            _delay = false
        },2000);
        var list = [];
        var object = {};
        object.proId = $("#proId").val();
        object.taskId = "16";
        object.content = $('#openTime').val().trim();
        object.taskName = "确认开业时间";
        if ($('#openTime').val() != null && $('#openTime').val() != "") {
            list.push(object);
        }
        var openTime = $('#openTime').val();
        if (openTime == '') {
            layer.msg('确认开业时间', {icon: 2},)
            return
        } else {
            $.ajax({
                type: "post",
                url: "/task/addRentAdmin",
                data: JSON.stringify(list),
                contentType: 'application/json',
                async: false,
                success: function (rs) {
                    if(rs.success){
                        list = [];
                        layer.msg('提交成功！', {icon: 1},);
                        $('#16').hide();
                        $('#dt').css('color', '#64a84d');
                        $('#dtSpan').css('color', '#64a84d');
                        window.location.reload();
                    }else{
                        Feng.error(rs.message);
                    }
                }, error: function (rs) {
                    list = [];
                    Feng.error(rs.responseJSON.message);
                    // window.location.reload();
                }
            });
        }

    });
    // 预估开业时间修改按钮是否显示
    $(function () {
        var yugu = $('#ygTime').val()
        if ( yugu == '' ){
           $('#yg').hide()
        } else {
            $('#yg').css('display','block')
        }
    });
    // 预估开业时间修改
    var _delay = false
    $('#yg').click(function () {
        if(_delay) {
            layer.msg('请勿多次点击提交！');
            return;
        };
        _delay = true;
        setTimeout(() =>{
            _delay = false
        },2000);
        layer.open({
            type: 1,
            area: ['200px', '200px'],
            btnAlign: 'c',
            btn: ['确认', '取消'],
            content: '<p style="text-align: center;padding-top: 40px;">确定修改吗？</p>'
            ,yes: function(index, layero){
                var list = [];
                var object = {};
                object.proId = $("#proId").val();
                object.taskId = "22";
                object.content = $('#ygTime').val().trim();
                object.taskName = "预估开业时间";
                if ($('#ygTime').val() != null && $('#ygTime').val() != "") {
                    list.push(object);
                }

                $.ajax({
                    type: "post",
                    url: "/task/editRent",
                    data: JSON.stringify(list),
                    contentType: 'application/json',
                    async: false,
                    success: function () {
                        list = [];
                        layer.msg('提交成功！', {icon: 1},);
                        $('#dt').css('color', '#64a84d');
                        $('#dtSpan').css('color', '#64a84d');
                        $('.editDate').css("display","block");
                        window.location.reload();
                    }, error: function () {
                        list = [];
                        window.location.reload();
                    }
                });

            }
            ,btn2: function(index, layero){
                //按钮【按钮二】的回调

                //return false 开启该代码可禁止点击该按钮关闭
            }
        });

    });

    // 提食品经营许可证
    var _delay = false
    $('#44').click(function () {
        if(_delay) {
            layer.msg('请勿多次点击提交！');
            return;
        };
        _delay = true;
        setTimeout(() =>{
            _delay = false
        },2000);
        var dgztimg = $('#dgztimg').val();
        var wsrq = $('#wsrq').val();
        var list = [];
        $("#ws .name").each(function (o, e) {
            var object = {};
            object.proId = $("#proId").val();
            object.taskId = $(e).next().find('.taskId').val();
            object.content = $(e).next().find('.msg').val().trim();
            object.taskName = $(e).html().trim();
            if ($(e).next().find('.msg').val() != null && $(e).next().find('.msg').val() != "") {
                list.push(object);
            }
        });
        if (dgztimg == '') {
            layer.msg('请上传食品经营许可证！', {icon: 2},);
            return
        } else if (wsrq == '') {
            layer.msg('请填写食品经营许可证截止日期！', {icon: 2},);
            return
        } else {
            $.ajax({
                type: "post",
                url: "/task/addRentAdmin",
                data: JSON.stringify(list),
                contentType: 'application/json',
                async: false,
                success: function (rs) {
                    if(rs.success){
                        list = [];
                        layer.msg('提交成功！', {icon: 1},);
                        $('#44').hide();
                        window.location.reload();
                    }else{
                        Feng.error(rs.message);
                    }
                }, error: function (rs) {
                    list = [];
                    Feng.error(rs.responseJSON.message);
                    // window.location.reload();
                }
            });
        }

    });

    // 提交门店地址
    var _delay = false;
    $('#55').click(function () {
        if(_delay) {
            layer.msg('请勿多次点击提交！');
            return;
        };
        _delay = true;
        setTimeout(() =>{
            _delay = false
        },2000);
        var wwztimg = $('#wwztimg').val();
        var yyrq = $('#yyrq').val();
        var xsjztimg = $('#xsjztimg').val();
        var dzxm = $('#dzxm').val();
        var dzdh = $('#dzdh').val();
        var mddz = $('#mddz').val();
        var yyzzmc = $('#yyzzmc').val();
        var xydm = $('#xydm').val();
        var yyzzdz = $('#yyzzdz').val();
        var list = [];
        $("#oneAll .name").each(function (o, e) {
            var object = {};
            object.proId = $("#proId").val();
            object.taskId = $(e).next().find('.taskId').val();
            object.content = $(e).next().find('.msg').val().trim();
            object.taskName = $(e).html().trim();
            if ($(e).next().find('.msg').val() != null && $(e).next().find('.msg').val() != "") {
                list.push(object);
            }
        });
        if (wwztimg == '') {
            layer.msg('请上传营业执照！', {icon: 2,});
            return
        } else if (yyrq == '') {
            layer.msg('请填写营业执照年审日期！', {icon: 2,});
            return
        } else if (xsjztimg == '') {
            layer.msg('请上传法人身份证！', {icon: 2,});
            return
        } else if (dzxm == '') {
            layer.msg('请填写店长姓名！', {icon: 2,});
            return
        } else if (dzdh == '') {
            layer.msg('请填写店长电话！', {icon: 2,});
            return
        } else if (mddz == '') {
            layer.msg('请填写门店地址！', {icon: 2,});
            return
        }else if (yyzzmc == '') {
            layer.msg('请填写营业执照名称！', {icon: 2,});
            return
        } else if (xydm == '') {
            layer.msg('请填写统一社会信用代码！', {icon: 2,});
            return
        } else {
            $.ajax({
                type: "post",
                url: "/task/addRentAdmin",
                data: JSON.stringify(list),
                contentType: 'application/json',
                async: false,
                success: function (rs) {
                    if(rs.success){
                        list = [];
                        layer.msg('提交成功！', {icon: 1},);
                        $('#55').hide();
                        window.location.reload();
                    }else{
                        Feng.error(rs.message);
                    }
                }, error: function (rs) {
                    list = [];
                    Feng.error(rs.responseJSON.message);
                    // window.location.reload();
                }

            });
        }

    });

    function updateTaskStatus(){
        const id = $("#proId").val();
        $.ajax({
            type: "get",
            url: "/btyDoubleCard/updateTaskStatus?proId="+id,
            contentType: 'application/json',
            async: false,
            success: function (res) {
            }, error: function (err) {}
        });
    }

    // 修改门店地址
    var _delay = false;
    $('#ying').click(function () {
        if(_delay) {
            layer.msg('请勿多次点击提交！');
            return;
        };
        _delay = true;
        setTimeout(() =>{
            _delay = false
        },2000);
        var list = [];
        $("#oneAll .name").each(function (o, e) {
            var object = {};
            object.proId = $("#proId").val();
            object.taskId = $(e).next().find('.taskId').val();
            object.content = $(e).next().find('.msg').val().trim();
            object.taskName = $(e).html().trim();
            if ($(e).next().find('.msg').val() != null && $(e).next().find('.msg').val() != "") {
                list.push(object);
            }
        });
        $.ajax({
            type: "post",
            url: "/task/editRent",
            data: JSON.stringify(list),
            contentType: 'application/json',
            async: false,
            success: function () {
                list = [];
                layer.msg('提交成功！', {icon: 1},);
                updateTaskStatus()
                $('#55').hide();
                $(".editBox").css("display","block");
                window.location.reload();
            }, error: function () {
                list = [];
                window.location.reload();
            }
        });
    });

    // 开业时间修改
    var _delay = false
    $('#ky').click(function () {
        if(_delay) {
            layer.msg('请勿多次点击提交！');
            return;
        };
        _delay = true;
        setTimeout(() =>{
            _delay = false
        },2000);
        var list = [];
        var object = {};
        object.proId = $("#proId").val();
        object.taskId = "16";
        object.content = $('#openTime').val().trim();
        object.taskName = "确认开业时间";
        if ($('#openTime').val() != null && $('#openTime').val() != "") {
            list.push(object);
        }
        $.ajax({
            type: "post",
            url: "/task/editRent",
            data: JSON.stringify(list),
            contentType: 'application/json',
            async: false,
            success: function () {
                list = [];
                layer.msg('提交成功！', {icon: 1},);
                $('#16').hide();
                $('#dt').css('color', '#64a84d');
                $('#dtSpan').css('color', '#64a84d');
                $('.editDate').css("display","block");
                window.location.reload();
            }, error: function () {
                list = [];
                layer.msg('提交失败！');
                window.location.reload();
            }
        });

    });

// 宿舍信息修改
    var _delay = false
    $("#sushe").click(function () {
        if(_delay) {
            layer.msg('请勿多次点击提交！');
            return;
        };
        _delay = true;
        setTimeout(() =>{
            _delay = false
        },2000);
        var list = [];
        $("#zf .name").each(function (o, e) {
            var object = {};
            object.proId = $("#proId").val();
            object.taskId = $(e).next().find('.taskId').val();
            object.content = $(e).next().find('.msg').val().trim();
            object.taskName = $(e).html().trim();
            if ($(e).next().find('.msg').val() != null && $(e).next().find('.msg').val() != "") {
                list.push(object);
            }
        });

        $.ajax({
            type: "post",
            url: "/task/editRent",
            data: JSON.stringify(list),
            contentType: 'application/json',
            async: false,
            success: function () {
                list = [];
                layer.msg('提交成功！', {icon: 1},);
                $('#23').hide();
                $('.editSushe').css("display","block");
                window.location.reload();
            }, error: function () {
                list = [];
                window.location.reload();
            }
        });

    });

    // 提食品经营许可证修改
    var _delay = false
    $('#weiS').click(function () {
        if(_delay) {
            layer.msg('请勿多次点击提交！');
            return;
        };
        _delay = true;
        setTimeout(() =>{
            _delay = false
        },2000);
        var list = [];
        $("#ws .name").each(function (o, e) {
            var object = {};
            object.proId = $("#proId").val();
            object.taskId = $(e).next().find('.taskId').val();
            object.content = $(e).next().find('.msg').val().trim();
            object.taskName = $(e).html().trim();
            if ($(e).next().find('.msg').val() != null && $(e).next().find('.msg').val() != "") {
                list.push(object);
            }
        });
        $.ajax({
            type: "post",
            url: "/task/editRent",
            data: JSON.stringify(list),
            contentType: 'application/json',
            async: false,
            success: function () {
                list = [];
                layer.msg('提交成功！', {icon: 1},);
                updateTaskStatus()
                $('#44').hide();
                $('.editWs').css("display","block");
                window.location.reload();
            }, error: function () {
                list = [];
                window.location.reload();
            }
        });

    });


    // 股份是否交齐
    var _delay = false;
    $('#18').click(function () {
        if(_delay) {
            layer.msg('请勿多次点击提交！');
            return;
        };
        _delay = true;
        setTimeout(() =>{
            _delay = false
        },2000);
        var list = [];
        var object = {};
        object.proId = $("#proId").val();
        object.taskId = '18';
        object.content = '股份已缴齐';
        object.taskName = '股份是否缴齐';
        if ($('#shares').val() != null && $('#shares').val() != "") {
            list.push(object);
        }
        $.ajax({
            type: "post",
            url: "/task/addRentAdmin",
            data: JSON.stringify(list),
            contentType: 'application/json',
            async: false,
            success: function (rs) {
                if(rs.success){
                    list = [];
                    layer.msg('已确认！', {icon: 1},);
                    $('#18').hide();
                    window.location.reload();
                }else{
                    Feng.error(rs.message);
                }
            }, error: function (rs) {
                list = [];
                Feng.error(rs.responseJSON.message);
                // window.location.reload();
            }
        });
    });

    // 收银系统
    var _delay = false;
    $('#21').click(function () {
        if(_delay) {
            layer.msg('请勿多次点击提交！');
            return;
        };
        _delay = true;
        setTimeout(() =>{
            _delay = false
        },2000);
        var list = [];
        var object = {};
        object.proId = $("#proId").val();
        object.taskId = '21';
        object.status = 2;
        if ($("#name").val() == "刘书伟") {
            object.content = '收银账号已建完，收银档案未建完';
        } else {
            object.content = '收银档案已建完';
        }
        object.taskName = '收银系统';
        list.push(object);
        $.ajax({
            type: "post",
            url: "/task/addRentAdmin",
            data: JSON.stringify(list),
            contentType: 'application/json',
            async: false,
            success: function (rs) {
                if(rs.success){
                    list = [];
                    layer.msg('已确认！', {icon: 1},);
                    $('#21').hide();
                    window.location.reload();
                }else{
                    Feng.error(rs.message);
                }
            }, error: function (rs) {
                list = [];
                Feng.error(rs.responseJSON.message);
                // window.location.reload();
            }
        });
    });

    // 当地供货商
    var _delay = false;
    $('#17').click(function () {
        if(_delay) {
            layer.msg('请勿多次点击提交！');
            return;
        };
        _delay = true;
        setTimeout(() =>{
            _delay = false
        },2000);
        var list = [];
        var object = {};
        object.proId = $("#proId").val();
        object.taskId = '17';
        object.content = '已确认';
        object.taskName = '当地供货商';
        if ($('#supplier').val() != null && $('#supplier').val() != "") {
            list.push(object);
        }
        $.ajax({
            type: "post",
            url: "/task/addRentAdmin",
            data: JSON.stringify(list),
            contentType: 'application/json',
            async: false,
            success: function (rs) {
                if(rs.success){
                    list = [];
                    layer.msg('已确认！', {icon: 1},);
                    $('#17').hide();
                    window.location.reload();
                }else{
                    Feng.error(rs.message);
                }
            }, error: function (rs) {
                list = [];
                Feng.error(rs.responseJSON.message);
                // window.location.reload();
            }
        });
    });

    // 网上建店
    var _delay = false;
    $('#36').click(function () {
        if(_delay) {
            layer.msg('请勿多次点击提交！');
            return;
        };
        _delay = true;
        setTimeout(() =>{
            _delay = false
        },2000);
        var list = [];
        var object = {};
        object.proId = $("#proId").val();
        object.taskId = '36';
        object.content = '已确认';
        object.taskName = '网上建店';
        if ($('#shop').val() != null && $('#shop').val() != "") {
            list.push(object);
        }
        $.ajax({
            type: "post",
            url: "/task/addRentAdmin",
            data: JSON.stringify(list),
            contentType: 'application/json',
            async: false,
            success: function (rs) {
                if(rs.success){
                    list = [];
                    layer.msg('已确认！', {icon: 1},);
                    $('#36').hide();
                    window.location.reload();
                }else{
                    Feng.error(rs.message);
                }
            }, error: function (rs) {
                list = [];
                Feng.error(rs.responseJSON.message);
                // window.location.reload();
            }
        });
    });

    // 线上套餐
    var _delay = false;
    $('#37').click(function () {
        if(_delay) {
            layer.msg('请勿多次点击提交！');
            return;
        };
        _delay = true;
        setTimeout(() =>{
            _delay = false
        },2000);
        var list = [];
        var object = {};
        object.proId = $("#proId").val();
        object.taskId = '37';
        object.content = '已确认';
        object.taskName = '线上套餐';
        if ($('#surMeal').val() != null && $('#surMeal').val() != "") {
            list.push(object);
        }
        $.ajax({
            type: "post",
            url: "/task/addRentAdmin",
            data: JSON.stringify(list),
            contentType: 'application/json',
            async: false,
            success: function (rs) {
                if(rs.success){
                    list = [];
                    layer.msg('已确认！', {icon: 1},);
                    $('#37').hide();
                    window.location.reload();
                }else{
                    Feng.error(rs.message);
                }
            }, error: function (rs) {
                list = [];
                Feng.error(rs.responseJSON.message);
                // window.location.reload();
            }
        });
    });

    // 排队机
    var _delay = false;
    $('#38').click(function () {
        if(_delay) {
            layer.msg('请勿多次点击提交！');
            return;
        };
        _delay = true;
        setTimeout(() =>{
            _delay = false
        },2000);
        var list = [];
        var object = {};
        object.proId = $("#proId").val();
        object.taskId = '38';
        object.content = '已确认';
        object.taskName = '排队机';
        if ($('#queuing').val() != null && $('#queuing').val() != "") {
            list.push(object);
        }
        $.ajax({
            type: "post",
            url: "/task/addRentAdmin",
            data: JSON.stringify(list),
            contentType: 'application/json',
            async: false,
            success: function (rs) {
                if(rs.success){
                    list = [];
                    layer.msg('已确认！', {icon: 1},);
                    $('#38').hide();
                    window.location.reload();
                }else{
                    Feng.error(rs.message);
                }
            }, error: function (rs) {
                list = [];
                Feng.error(rs.responseJSON.message);
                // window.location.reload();
            }
        });
    });

    // 确认到货
    var _delay = false;
    $('#dh').click(function () {
        if(_delay) {
            layer.msg('请勿多次点击提交！');
            return;
        };
        _delay = true;
        setTimeout(() =>{
            _delay = false
        },2000);
        var object = {};
        var list = [];
        object.proId = $("#proId").val();
        object.taskId = 15;
        if ($('#arrival').val() != null && $('#arrival').val() != "") {
            list.push(object);
        }
        $.ajax({
            type: "post",
            url: "/task/editRent",
            contentType: 'application/json',
            data: JSON.stringify(list),
            async: false,
            success: function (rs) {
                if(rs.success){
                    layer.msg('已确认！', {icon: 1},);

                    window.location.reload();
                }else{
                    Feng.error(rs.message);
                }
            }, error: function (rs) {
                Feng.error(rs.responseJSON.message);
                // window.location.reload();
            }
        });
    });
    // 获取时间
    $(function () {
      var a=  $('#distribution').val();
        if ( a == ''){
            $('#dh').attr("disabled", "disabled");
            $('#dh').css('background','#E1E3E6');
        }
    });
    // 配送要货
    var _delay = false;
    $('#15').click(function () {
        if(_delay) {
            layer.msg('请勿多次点击提交！');
            return;
        };
        _delay = true;
        setTimeout(() =>{
            _delay = false
        },2000);
        var list = [];
        var object = {};
        object.proId = $("#proId").val();
        object.taskId = '15';
        object.content = $('#distribution').val();
        object.note = $('#note').val().trim();
        object.taskName = '配送到货日期';
        if ($('#distribution').val() != null && $('#distribution').val() != "") {
            list.push(object);
        }
        $.ajax({
            type: "post",
            url: "/task/addRentAdmin",
            data: JSON.stringify(list),
            contentType: 'application/json',
            async: false,
            success: function () {
                list = [];
                layer.msg('已提交！', {icon: 1},);
                $('#15').hide();
                window.location.reload();
            }, error: function () {
                list = [];
                window.location.reload();
            }
        });
    });
    // 到货时间修改
    var _delay = false
    $('#ps').click(function () {
        if(_delay) {
            layer.msg('请勿多次点击提交！');
            return;
        };
        _delay = true;
        setTimeout(() =>{
            _delay = false
        },2000);
        var list = [];
        var object = {};
        object.proId = $("#proId").val();
        object.taskId = "15";
        object.content = $('#distribution').val().trim();
        object.note = $('#note').val().trim();
        object.taskName = "配送到货日期";
        if ($('#distribution').val() != null && $('#distribution').val() != "") {
            list.push(object);
        }
        $.ajax({
            type: "post",
            url: "/task/editRent",
            data: JSON.stringify(list),
            contentType: 'application/json',
            async: false,
            success: function () {
                list = [];
                layer.msg('提交成功！', {icon: 1},5000);
                $('#15').hide();
                $('#dt').css('color', '#64a84d');
                $('#dtSpan').css('color', '#64a84d');
                $('.editDateps').css("display","block");
                window.location.reload();
            }, error: function () {
                list = [];
                layer.msg('提交失败！',);
                window.location.reload();
            }
        });

    });

    // //网上建店
    // $("#shop").click(function () {
    //     window.location.href = Feng.ctxPath + '/project/internetStore?id=' + $("#proId").val() + "&content=" + $("#36").val() + "&role=" + $("#role").val();
    // });
    //
    // //线上套餐
    // $("#surMeal").click(function () {
    //     window.location.href = Feng.ctxPath + '/project/surfMeal?id=' + $("#proId").val() + "&content=" + $("#37").val() + "&role=" + $("#role").val();
    // });
    //
    // //排队机
    // $("#queuing").click(function () {
    //     window.location.href = Feng.ctxPath + '/project/queuing?id=' + $("#proId").val() + "&content=" + $("#38").val() + "&role=" + $("#role").val();
    // });

    //返回按钮
    $("#backupPage").click(function () {
        window.location.href = Feng.ctxPath + '/project/adminPage?bf=b'
    });
});

